<?PHP
$PurviewLevel=0;
require("../../inc/common.inc.php");
require_once(dirname(__FILE__)."/../"."Admin_ChkPurview.php");
if(intval($pagetype)==0){$pagetype=2;}
$poststr = "&type=".$type."&pagetype=".$pagetype."&keyword=".$keyword;
$poststr2 = "&type=".$type."&keyword=".$keyword;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理-营销阵营</title>
<link href="../images/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php require("../mx_head.php") ;
if ($action=="work"){
    //设置推荐
	if(!$listdb&&!$id){
		$fun->popmassage("请选择一条信息","","popback");
		exit();
	}
	elseif(is_array($listdb))
	{
		foreach($listdb AS $key=>$value){
			$replyinfo = $db->excu("select * from mx_tuisong_reply where rsucaiid='".$key."'");
			$menuinfo = $db->excu("select * from mx_weixin_menu where mtsucaiid='".$key."'");
			if(!$replyinfo||!$menuinfo){
			dowork($key,$jobs);
			}
		}
	}elseif($id){
		$replyinfo = $db->excu("select * from mx_tuisong_reply where rsucaiid='".$id."'");
		$menuinfo = $db->excu("select * from mx_weixin_menu where mtsucaiid='".$id."'");
		if(!$replyinfo||!$menuinfo){
		dowork($id,$jobs);
		}else{
			$fun->popmassage("该素材正在使用中不可删除","","popback");
		exit();
		}
	}
	$url=$fromurl?$fromurl:$FROMURL;
	jump2("操作成功，已自动过滤使用中的素材",$url,1);

}

function dowork($id,$job){
	global $db,$pre,$timestamp,$userdb,$webdb,$fiddbadmin,$Purview,$fun,$OtherPurview,$Purview,$usersql;
	$rsdb=$db->get_one("SELECT * FROM mx_sucai_file WHERE fid='$id'");
	if($job=="delete")
	{
	    if (strpos("****".$OtherPurview,'shenhe')<=0 and $Purview!=1 and $Purview!=3){
		    $fun->popmassage("您没有此项管理权限","","popback");
		    exit();
		}
		$db->excu("DELETE FROM mx_sucai_file WHERE fid='$id'");
	}
}
?>
	<div class="right">
	  <div class="gk">
			<div class="ti2 fl">语音素材</div>
			<ul class="fr">
				<li><span class="c1"><?php echo $db->num_rows($db->excu("select fid from mx_sucai_file where ftype=3"));?></span><span>素材总条数</span></li>
			</ul>
			<div class="clear"></div>
	  </div>
		<div class="height15"></div>
		<div class="xm2">
			<h1 class="fl">语音上传</h1>
			<!--<span class="fr"><a href="#"><img src="../images/right_4.png" alt="设置" /></a></span>-->
			<div class="clear"></div>
		</div>
		<div class="xm2_b">
		  
			<div class="height15"></div>
				<script type="text/javascript" src="../js/jquerys-1.5.1.js"></script>
				<script language="javascript">
				function showimg(fid,fsrc,label){
					document.getElementById(label).value=fid;
					document.getElementById(label+"3").src=fsrc;
					document.getElementById(label+"2").style.display="block";
				}
				function reurl(editid){
					document.location="sucai_edit.php?id="+editid;
				}
				</script>
				<form id="form2" name="form2" method="post" action="">
				  <table width="100%" border="0" align="left" cellpadding="9" cellspacing="0">
                    <tr>
                      <td width="143" align="right" class="font14"> 语音：</td>
                      <td width="200"><button type="button" class="button1">上传</button><iframe id="uploadIframe" style="filter:alpha(opacity = 0);-moz-opacity:0;-khtml-opacity:0;opacity:0;overflow:hidden;z-index:99;position:absolute;left:170px;width:93px;height:28px;" class="uploadfile" src="sucai_upload.php?type=3&formId=1&fn=reurl&dir=sucai&label=mpic"></iframe></td>
                      <td class="font12">语音大小限制：5M， 长度限制：60s， 支持格式：mp3, wma, wav, amr</td>
                    </tr>
                    <tr>
                      <td colspan="3" height="20">&nbsp;</td>
                    </tr>
                  </table>
          </form>
				<div class="height15"></div>
	  </div>
		<div class="height15"></div>
		<div class="xm2">
			<h1 class="fl">信息列表</h1>
			<!--<span class="fr"><a href="#"><img src="../images/right_4.png" alt="设置" /></a></span>-->
		</div>
        
		<div class="xm2_b">
			<div class="t">
				<div class="l1 fl"><select onChange="javascript:window.location=this.value;"><option value="sucai_music.php?pagetype=1<?php echo $poststr2;?>" <?php echo $pagetype==1?'selected="selected"':'';?>>10</option><option value="sucai_music.php?pagetype=2<?php echo $poststr2;?>" <?php echo $pagetype==2?'selected="selected"':'';?>>20</option></select></div>
				<div class="l2 fl">选择每页的信息数量，默认值为：20条/页。</div>
				<div class="l3 fr"><div class="l">快速检索: </div><div class="r"><input name="keyword" type="text" value="<?php echo $keyword;?>" onkeydown="setTrack(this,event)" /></div></div>
				<div class="clear"></div>
			</div>
			<div class="height15"></div>
				<script type="text/javascript" src="../js/jquerys-1.5.1.js"></script>
                <script language="javascript">
				function setTrack(tt,event){
				var e = event?event:window.event
				if(e.keyCode == 13){
				window.location="sucai_music.php?type=title&pagetype=<?php echo $pagetype;?>&keyword="+tt.value;
				}
				}
				</script>
                <script language="javascript">
				function postdo(va){
					if (va=="delete"){
						if(!confirm("您确认要删除这些记录吗?")){
						return false;
						}
					}
					document.form1.jobs.value=va
					document.form1.submit();
				}
				
				function CheckAll(va,zt){
					form=document.form1
					for (var i=0;i<form.elements.length;i++){
						var e = form.elements[i];
						if(va=='all'){
							e.checked = zt;
						}else{
							e.checked == true ? e.checked = false : e.checked = true;
						}
					}
				}
				function subform(){
						 if(document.all.type.value==""){
							alert("请选择查询条件！");
							return false;
						 }
						document.form2.submit();
				}
				</script>
                <form name="form1" action="sucai_pic.php?action=work<?php echo $poststr;?>" method="post">
                 <input type="hidden" name="jobs" value="">
			<table width="98%" border="0" align="center" cellpadding="9" cellspacing="1" bgcolor="#CCCCCC" class="stripe">
			  <tr>
				<th width="4%" align="center" ><input type="checkbox" name="checkbox" class="ri" onClick="CheckAll('all',this.checked)" /><input type="hidden" name="editid" id="editid" value="0"></th>
				<!--<th width="4%" align="center" class="table_ti">ID</th>-->
                <th align="center" class="table_ti">素材名称</th>
				<!--<th width="15%" align="center" class="table_ti">缩略图</th>-->
                <th width="10%" align="center" class="table_ti">大小</th>
                <th width="10%" align="center" class="table_ti">添加时间</th>
				<th width="17%" align="center" class="table_ti">操作</th>
			  </tr>
              <script>
				
				var ddkey=0;
				var xmlobj; //定义XMLHttpRequest对象
				function CreateXMLHttpRequest()
				{
				if(window.XMLHttpRequest)
				{//Mozilla浏览器
				xmlobj=new XMLHttpRequest();
				if(xmlobj.overrideMimeType)
				{//设置MIME类别
				xmlobj.overrideMimeType("text/xml");
				}
				}
				else if(window.ActiveXObject)
				{ //IE浏览器
				try
				{
				xmlobj=new ActiveXObject("Msxml2.XMLHttp");
				}
				catch(e)
				{
				try
				{
				xmlobj=new ActiveXobject("Microsoft.XMLHttp");
				}
				catch(e)
				{
				}
				}
				}
				
				}
				function editname(fid){
					
					if(ddkey==1){return false;}
					ddkey=1;
					
					document.getElementById("showname"+fid).style.display="none";
					document.getElementById("editname"+fid).style.display="block";
					document.getElementById("editid").value=fid;
					document.getElementById("fname"+fid).focus();
				}
				function checkeidt(val){
					fid = document.getElementById("editid").value;
					if(val==""){
						document.getElementById("fname"+fid).focus();
						alert("名称不能为空");
						return false;
					}
					CreateXMLHttpRequest(); 
					var showurl = "editname.php?fid="+fid+"&val="+encodeURI(encodeURI(val)); 
					xmlobj.open("GET", showurl, true);
					xmlobj.onreadystatechange = after_checkeidt; 
					xmlobj.send(null); 
				}
				function after_checkeidt() { //用于处理状态的函数
				if(xmlobj.readyState == 4 && xmlobj.status == 200) //如果URL成功访问，则输出网页 
				{	
					ss=xmlobj.responseText;
					if (ss=="1"){
						fid = document.getElementById("editid").value;
						document.getElementById("showname"+fid).style.display="block";
						document.getElementById("showname"+fid).innerHTML=document.getElementById("fname"+fid).value;
						document.getElementById("editname"+fid).style.display="none";
						
					}else{
						alert("参数错误");
					}
					ddkey = 0;
				}
				}
				var html = new Array();　
				</script>
              <?php
			  if(empty($pageindex)){$pageindex=1;}
			  $str=" and ftype=3";
			  if($type=="yz"){
				  $str.=" AND isok=1 ";
			  }
			  elseif($type=="unyz"){
				  $str.=" AND isok=0 ";
			  }
			  elseif($type=="title"){
				  $str.=" AND fname LIKE '%$keyword%' ";
			  }
			  $order="order by addtime desc, fid desc";
			  $pagesize = $pagetype==1?"10":"20";
			  $table=" mx_sucai_file ";
			  $column=" * ";
			  $c=$db->listcount($table,$str);
			  $list=$db->list1($pageindex,$pagesize,$table,$column,$str,$order);
			  if(!is_array($list) or $c==0){
				echo "<tr><td colspan='10'><p style='height:30px;text-align:center;line-height:30px;'>暂无信息</p></td></tr>";
			  }
			  else{
			  for($i=0;$i<count($list);$i++){
			  ?>
               <script language="javascript">
			  var showcon = '<iframe src="get_mobileshow.php?id=<?php echo $list[$i]["fid"];?>&type=music" id="showpiciframe" class="showbox" frameborder="0"></iframe>';
			  html.push(showcon);
              </script>
			  <tr>
				<td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="listdb[<?php echo $list[$i]["fid"];?>]" value="<?php echo $list[$i]["fid"];?>" class="ri" /></td>
				<!--<td align="center" bgcolor="#FFFFFF" class="font14"><?php echo $list[$i]["fid"];?></td>-->
				<td align="center" bgcolor="#FFFFFF" class="font14">
                <div id="showname<?php echo $list[$i]["fid"];?>">
				<?php echo $list[$i]["fname"];?>
                </div>
                <div id="editname<?php echo $list[$i]["fid"];?>" style="display:none;">
				<input type="text" name="fname" id="fname<?php echo $list[$i]["fid"];?>" value="<?php echo $list[$i]["fname"];?>" size="70" onblur="checkeidt(this.value)">
                </div>
                </td>
				<!--<td align="center" bgcolor="#FFFFFF"><img src="<?php echo $list[$i]["fpath"]?>" width="100"/></td>-->
                <td align="center" bgcolor="#FFFFFF" class="font14"><?php echo round($list[$i]["fsize"]/1024,2);?>k</td>
				<td align="center" bgcolor="#FFFFFF" class="font12"><?php echo date("Y-m-d",$list[$i]["addtime"])?></td>
				<td align="left" bgcolor="#FFFFFF"><a href="javascript:void(0)" onclick='showBox(200,265,"<?php echo $i;?>");'><img src="../images/imgyl.gif" width="11" height="11" /> 播放</a>&nbsp;&nbsp;<a href="download.php?fid=<?php echo $list[$i]["fid"];?>" target="_blank">下载</a>&nbsp;&nbsp;<a href="sucai_edit.php?id=<?php echo $list[$i]["fid"];?>">编辑</a>&nbsp;&nbsp;<a href="sucai_pic.php?action=work&jobs=delete&id=<?php echo $list[$i]["fid"]?><?php echo $poststr;?>" onClick="return confirm('删除后不可恢复,你确实要删除吗?')">删除</a><?php echo $mtypestr;?></td>
			  </tr>
              
			  <?php
			  }
			  }
			  ?>
			</table>
            <script type="text/javascript" src="../js/lightBox.js"></script>
				<script>
				function showBox(conwidth,conheight,showid){
					showcon = html[showid];
					Box("mobile",conwidth,conheight,showcon,"");
				}
				</script>
            </form>
			<div class="height15"></div>
			<div class="b">
				<div class="l fl"><input name="" type="checkbox" onClick="CheckAll('all',this.checked)" /></div>
				<div class="c fl">批量选择</div>
				<div class="r fl">选择操作：<a href="javascript:void(0)" onClick="postdo('delete')">全部删除</a><input type="hidden" name="jobs" value="0"></div>
			</div>
			<div class="height15"></div>
			<div class="pagination">
				<?php if ($c>$pagesize){echo $db->ThePage_mxsoft($s,$pageindex,$c,$pagesize,'','',0,4,''.$poststr.'');}?>
			</div>
            <div class="clear"></div>
			<div class="height15"></div>
		</div>
        
		<div class="clear"></div>
  <?php require("../mx_foot.php") ;?>
  </div>
</body>
</html>
